package com.ipartek.pruebas.bbddaccessP1;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

import com.ipartek.pruebas.bean.CursoP1;

public class CursoOBDCDAOP1 implements CursoDAOP1{
	
	Connection con;
	PreparedStatement ptmt = null;
	ResultSet result = null;
	
	public CursoOBDCDAOP1(){
		
	}
	
	public List<CursoP1> getCursos(){
		List<CursoP1> list = new ArrayList<CursoP1>();
		
		con = OBDCDAOFactoryP1.getConnection();
		String sql = "SELECT * FROM Curso";
		try{
		ptmt = con.prepareStatement(sql);
		result = ptmt.executeQuery();
		while(result.next()){
			CursoP1 c = new CursoP1();
			c.setCodigo(result.getString(1));
			c.setDescripcion(result.getString(3));
			c.setMaxAlumnos(result.getInt(6));
			list.add(c);
			
		}
		}catch (SQLException e) {
			e.printStackTrace();
		}
		
		return list;
	}
}
